package org.csu.group4.jpetstore.persistence;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.csu.group4.jpetstore.mybatis.entity.Item;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface ItemDAO {
    @Insert("insert item(itemid, productid_id, listprice, supplier_id, status, attr1) values(#{itemid}, #{product.id}, #{listprice}, #{unitcost}, #{supplier.id}, #{status}, #{attr1})")
    void addItem(Item item);

    @Update("update item set listprice=#{listprice}, unitcost=#{unitcost}, status=#{status}, attr1=#{attr1} where itemid=#{itemid}")
    void updateItem(Item item);

    @Update("update item set status=#{status} where itemid=#{itemid}")
    void updateItemStatus(Item item);

    @Select("select * from item where productid = #{productId}")
    List<Item> getItemListByProduct(String productId);

    @Select("select * from item where itemid = #{itemid}")
    Item getItem(String itemId);

}
